
class WishListsController < ApplicationController
  before_filter :authenticate_user!

  def show
    @wish_list = wish_list

    render :json => @wish_list
  end

  def update
    @wish_list = wish_list
    if @wish_list.update_attributes(params[:wish_list])
      head :ok
    else
      render :json => @wish_list.errors, :status => :unprocessable_entity
    end
  end

  def destroy
    @wish_list = wish_list
    if @wish_list.destroy
      head :ok
    else
      render :json => @wish_list.errors, :status => :unprocessable_entity
    end
  end

  private
    def wish_list user = nil
      user ||= current_user

      return params[:name] && WishList.find_by_user_id_and_name(user.id, params[:name]) || user.wish_list
    end
end
